package com.alvin.demo.bean;

import com.alvin.demo.utils.NumberUtils;
import com.alvin.demo.utils.Tcp_Utils_Nio;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@NoArgsConstructor
public class RequestEntity {
    // 终端ID
    private String endPointId ;
    // 指令
    private String command ;
    // 网关Ip
    private String serverIp ;
    // 延迟读取时间
    private int timeOut ;

    private String crcType = "small" ; // 大端还是小端

    private Tcp_Utils_Nio tcp_utils ;

    public String getTotalCommand(){
        if (this.endPointId != null && !this.endPointId.isEmpty()){
            String hexString = NumberUtils.longToHexString(Long.parseLong(this.endPointId), 8);
            hexString = (hexString + " " + this.command ).toUpperCase().replace(" " , "");
            return tcp_utils.getTotalsCommand(hexString , crcType) ;
        }
        return "" ;
    }
    public String getResult() throws Exception {
        String hexString = NumberUtils.longToHexString(Long.parseLong(this.endPointId) , 8);
        String commandStr = hexString + " " + this.command;
        return tcp_utils.sendCommand(this.serverIp,8886, commandStr, this.timeOut , crcType);
    }

}
